const express = require('express')
let app = express()
const session = require('express-session')
const bodyparser = require('body-parser')
const cors = require('cors')
let apirouter = require('./router/api/api.js')
let webrouter = require('./router/web/web.js')

// 静态资源目录
app.use(express.static(__dirname + '/public'))
// 配置ejs引擎
app.set('view engine', 'ejs')
app.set('views', './views')
// 解析请求体中的json与urlencoded
app.use(express.json())
app.use(express.urlencoded({ extends: false }))

// 为请求报文挂在上session
// app.use(session({
//   secret: 'liangweijun',
//   resave: true,
//   saveUninitialized: false,
//   store: mongostore.create({
//     mongoUrl: 'mongodb://8.138.146.253:27017/mymongodb'
//   }),
//   cookie: {
//     secure: true,
//     maxAge: 1000 * 60 * 5
//   }
// }))
// 为请求报文挂在上body
app.use(bodyparser.urlencoded({ extended: false }))
app.use(bodyparser.json())
// 以下路由能实现跨域
app.use(cors())

app.use('/api', apirouter)
app.use(webrouter)

app.listen(9000, function () {
  console.log('9000端口的监听已开启');
})
